<template>
  <view>
<!--    <view-->
<!--        v-if="show"-->
<!--        @click="close"-->
<!--        class="back"></view>-->
    <u-datetime-picker
        :show="show"
        v-model="birthday"
        mode="date"
        :min-date="minDate"
        :max-date="maxDate"
        @close="close"
        @cancel="close"
        :closeOnClickOverlay="true"
        @confirm="change"
    ></u-datetime-picker>
  </view>
</template>

<script>

export default {
  props: {
    userInfo:{
      type: Object,
      default: () => {
        return {
          gmtBirthday: 0,
          genderCode:"male"
        };
      }
    }
  },

  data() {
    return {
      show: false,
      mode: "single",
      birthday: 0,
      minDate: new Date(1949, 9, 1).getTime(),
      maxDate: new Date().getTime()
    };
  },
  mounted() {
    // 奖最大年份设置为今年的16年前
    let maxYear = new Date().getFullYear() - 16;
    // 获取当前年份
    let nowYear = new Date().getFullYear();
    // 获取当前月份
    let nowMonth = new Date().getMonth() + 1;
    // 获取当前日期
    let nowDate = new Date().getDate();
    this.maxDate = new Date(maxYear, nowMonth-1, nowDate).getTime();
  },
  methods:{
    open(){
      this.show = true;
      this.birthday = this.userInfo.gmtBirthday;
      console.log(this.birthday);
      this.$emit("open");
    },
    close(){
      this.show = false;
      this.$emit("close");
    },
    change(res){
      setTimeout(()=>{
        console.log(res.value);
        this.$emit("change",res.value);
      },100);
      this.close();
    }
  }
}
</script>

<style lang="scss" scoped>
.back{
  position: fixed;
  z-index: 999999;
  background-color: rgba(0,0,0,0.5);
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
}
.box{
  position: relative;
  background-color: #FFFFFF;
  padding: 0 20rpx 20rpx 20rpx;
  box-shadow: 0 10rpx 10rpx rgba(118, 118, 118, 0.1);
  border-radius: 0 0 20rpx 20rpx;
  text-align: center;

  .in-box{
    position: relative;
    padding: 20rpx 0;
  }

  .in-box:active{
    opacity: .5;
  }
}

.text{
  position: absolute;
  display: inline-block;
  right: 0;
  font-size: 22rpx;
}
</style>
